package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.OAuthClientFrom;
import com.moss.cloud.base.api.model.param.ClientPageParam;
import com.moss.cloud.base.biz.service.ISysClientService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ServiceList.BASE + "/client")
public class SysClientController {
    private final ISysClientService sysClientService;

    public SysClientController(ISysClientService sysClientService) {
        this.sysClientService = sysClientService;
    }

    /**
     * 客户端分页查询
     *
     * @param pageParam
     * @return
     */
    @PostMapping("/clientPage")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "客户端分页查询")
    public Result<?> clientPage(@RequestBody ClientPageParam pageParam) {
        return Result.success(sysClientService.clientPage(pageParam));
    }

    /**
     * 新增保存客户端
     *
     * @param clientFrom
     * @return
     */
    @PostMapping("/saveClient")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增保存客户端")
    public Result<?> saveClient(@RequestBody @Validated OAuthClientFrom clientFrom) {
        return Result.success(sysClientService.saveClient(clientFrom));
    }

    /**
     * 修改客户端
     *
     * @param clientFrom
     * @return
     */
    @PostMapping("/updateClient")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "修改客户端")
    public Result<?> updateClient(@RequestBody @Validated OAuthClientFrom clientFrom) {
        return Result.success(sysClientService.updateClient(clientFrom));
    }


    /**
     * 删除客户端
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeClient")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除客户端")
    public Result<?> removeClient(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(sysClientService.removeClient(baseFrom));
    }

    /**
     * 查看客户端秘钥
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/viewSecret")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查看客户端秘钥")
    public Result<?> viewClientSecret(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysClientService.viewClientSecret(baseFrom));
    }

    /**
     * 重置客户端秘钥
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/resetSecret")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "重置客户端秘钥")
    public Result<?> resetSecret(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysClientService.resetSecret(baseFrom));
    }
}
